<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>流程撤销</title>
    <#include "/pubHeadStyle.html">
</head>
<body>

<script type="text/html" template>
    <div class="ccpui-tablesize user">
        <table class="layui-table">
            <colgroup>
                <col width="10">
                <col width="200">
            </colgroup>
            <tbody>
            <tr id="sendMethod">
                <td class="layui-bg-gray">发送方式</td>
                <td>
                    <#list handlersMap?keys as key>
                    <input type="checkbox"  lay-filter="informType"name="informType" lay-skin="primary" value="${key}" checked="checked"/>
                    <span style="line-height: 28px;" id="msg">
                    ${handlersMap[key].title }
                    </span>
                    </#list>
                </td>
            </tr>
            <tr id="message">
            </tr>
            </tbody>
        </table>
    </div>
    <div style="text-align: center;position: absolute;bottom: 10px;left: 0px;width: 100%;">
        <a class="layui-btn" lay-event="recover" id="recover">
            <i class="layui-icon"></i>
            <span>撤销</span>
        </a>
        <a class="layui-btn layui-btn-danger" id="close">
            <i class="layui-icon"></i>
            <span id="closeSpan">取消</span>
        </a>
    </div>

</script>
<script>
    layui.config({
        base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index','table', 'layer', 'laydate', 'form', 'util', 'commons', 'setter', 'totalFilter', 'common'], function (d) {
        var layer = layui.layer;
        var $ = layui.$;
        var setter = layui.setter;

        var runId = "${runId}";
        var backToStart = "${backToStart}";

        checkRecover();

        function checkRecover() {
            $.ajax({
                url: serverPath.workflowPath + setter.workflowLinkPath + "processRun/checkRecover?runId=" + runId,
                type: "post",
                dataType: 'json',
                success: function (data) {
                    if (data.code == 1) {
                        $('#message').html('<th class="layui-bg-gray">不能撤销原因</th><td style="color: #af0000">'+data.msg+'</td>');
                        $('#sendMethod').hide();
                        $('#recover').hide();
                        $("#closeSpan").html("关闭");
                    } else {
                        $('#message').html('<th class="layui-bg-gray">撤销原因</th>  <td><textarea name="desc" placeholder="请输入内容" class="layui-textarea" id="recoverReason"></textarea></td>');
                    }
                },
                error: function (XMLHttpRequest) {
                    layer.alert("请求失败！" + XMLHttpRequest.status);
                }
            })
        }

        $("#recover").click(function () {
            if ($('#recoverReason').val() != null && $('#recoverReason').val() != '') {
                layer.confirm("确认要撤回该数据吗？", {title: '撤销确认'}, function () {
                    $.ajax({
                        url: serverPath.workflowPath + setter.workflowLinkPath + "processRun/recover",
                        type: "post",
                        data:{runId: runId, backToStart:backToStart,informType:$('input[name="informType"]').val(),opinion:$('#recoverReason').val()},
                        dataType: 'json',
                        success: function (data) {
                          //撤销成功的提示
                            if(data.code == 0){
                                layer.open({
                                    title: '提示'
                                    , content: data.msg
                                    , yes: function () {
                                        //如果设定了yes回调，需进行手工关闭
                                        parent.layer.closeAll();
                                        if(parent.top.location==parent.self.location){
                                            parent.layer.closeAll();
                                        }
                                    }
                                });
                            }else {
                                //撤销失败的提示
                                layer.open({
                                    title: '提示'
                                    , content: data.msg
                                    , yes: function () {
                                        //do something
                                        var index = parent.layer.getFrameIndex(window.name);
                                        parent.layer.close(index); //如果设定了yes回调，需进行手工关闭
                                    }
                                });
                            }
                        },
                        error: function (XMLHttpRequest) {
                            layer.alert("请求失败！" + XMLHttpRequest.status);
                        }
                    });
                });

            } else {
                layer.open({
                    title: '提示'
                    , content: '必须填写撤销原因！'
                });
            }

        });

        $("#close").click(function () {
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        });

    })


</script>
</body>
</html>